/*
 * Copyright 2018 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.rz.paas.test.inChannel.bottomMenuFragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Observer
import com.orhanobut.hawk.Hawk
import com.rz.paas.test.R
import com.rz.paas.test.bottomView.InChannelSettingDetailFragment
import com.rz.paas.test.constant.AppConstant
import com.rz.paas.test.inChannel.viewModel.CommunicationViewModel
import kotlinx.android.synthetic.main.activity_setting.*
import kotlinx.android.synthetic.main.fragment_streaming_setting.*

class StreamingSettingFragment : MiddleFragment() {

    val communicationViewModel by activityViewModels<CommunicationViewModel>()

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {

        return inflater.inflate(R.layout.fragment_streaming_setting,container,false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        val dataMap = AppConstant.dataMap
        encode_resolution_place_holder.setOnClickListener {
            val optionIndex = AppConstant.ENCODE_RESOLUTION_DATA_INDEX
            val selected = Hawk.get(dataMap[optionIndex].name, 0) as Int
            InChannelSettingDetailFragment.newInstance(optionIndex, selected)
                .show(childFragmentManager, "...")
        }

        encode_fps_place_holder.setOnClickListener {
            val optionIndex = AppConstant.ENCODE_FPS_DATA_INDEX
            val selected = Hawk.get(dataMap[optionIndex].name, 0) as Int
            InChannelSettingDetailFragment.newInstance(optionIndex, selected)
                .show(childFragmentManager, "...")
        }

        encode_direction_place_holder.setOnClickListener {
            val optionIndex = AppConstant.ENCODE_DIRECTION_DATA_INDEX
            val selected = Hawk.get(dataMap[optionIndex].name, 0) as Int
            InChannelSettingDetailFragment.newInstance(optionIndex, selected)
                .show(childFragmentManager, "...")
        }

//        encode_resolution_choose.text = getResString(AppConstant.ENCODE_RESOLUTION_DATA_INDEX)

        communicationViewModel.encodeResolution.observe(viewLifecycleOwner, Observer {
            encode_resolution_choose.text = getResString(AppConstant.ENCODE_RESOLUTION_DATA_INDEX)
        })

//        encode_fps_choose.text = getResString(AppConstant.ENCODE_FPS_DATA_INDEX)

        communicationViewModel.encodeFPS.observe(viewLifecycleOwner, Observer {
            encode_fps_choose.text = getResString(AppConstant.ENCODE_FPS_DATA_INDEX)
        })


//        encode_direction_choose.text = getResString(AppConstant.ENCODE_DIRECTION_DATA_INDEX)

        communicationViewModel.encodeDirection.observe(viewLifecycleOwner, Observer {
            encode_direction_choose.text = getResString(AppConstant.ENCODE_DIRECTION_DATA_INDEX)
        })




    }

}
